<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算属性与侦听器</title>
    <script type="text/javascript" src="../JS/vue.js"></script>
</head>
<body>
<div id="root">
    姓<input v-model="firstname">
    名<input v-model="lastname">
    <div>{{fullname}}</div>
    <div>{{count}}</div>
</div>
<script type="text/javascript">
    new Vue({
        el:"#root",
        data:{
            firstname:'',
            lastname:'',
            count:0
        },
//        计算属性
        computed:{
            fullname:function () {
                return this.firstname+this.lastname
            }
        },
//        监听器
        watch:{
            firstname:function () {
                this.count++
            },
            lastname:function () {
                this.count++
            }
        }
    })
</script>
</body>
</html>